import tornado.web
import tornado.ioloop
import tornado.httpclient
from . import utils
import json
import threading
'''
#2.2 翻译接口　同步
    http://ip:port/txt/quickits
    {
        "itsType":"", #cnen cnug encn ugcn unkown
        "itsText":"",
    }

'''
class txtQuickits(tornado.web.RequestHandler):


    def post(self, *args, **kwargs):
        resp = None
        try:
            data=json.loads(self.request.body)
            print(data)
            paramerror = utils.checkParam(data, {
                "itsType":"", #cnen cnug encn ugcn unkown
                "itsText":"",
            })
            if paramerror == '':
                resp = {
                    "result":[
                        {
                            "index":0,
                            "src":"",
                            "target":"",
                            "state":{
                                "ok":1,
                                "failed":None
                            }
                        }
                    ],
                    "ok":1,"failed":''
                }
            else:
                resp = {
                    "ok":0,"failed": paramerror
                }

        except BaseException as e:
            resp = {
                "ok":0,"failed": str(e)
            }

        self.write(resp)
